import { STORAGE_AUTH } from '@/common/plugins/constant'

// 从 LocalStore 中获取储存的信息
const getIds = () => {
  const ids = localStorage.getItem(STORAGE_AUTH)
  return ids ? JSON.parse(ids) : {}
}

// 个人信息
export const getUserUtils = store => ({
  getUser: () => (store.getters.user.userId ? store.getters.user : getIds()),
  getUserId: () => store.getters.user.userId || getIds().userId,
  getUserName: () => store.getters.user.userName || getIds().userName,
  getJob: () => store.getters.user.job || getIds().job,
  getAddressCode: () => store.getters.user.queryAddressCode || getIds().queryAddressCode,
  getClientId: () => store.getters.org.clientId || getIds().clientId,
  getClientOrgClass: () => store.getters.org.orgClass || getIds().clientOrgClass,
  removeUser: () => {
    store.commit('user', {})
    localStorage.removeItem(STORAGE_AUTH)
  },
})
